package com.platform.comm.exceptions;

import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;

@SuppressWarnings("unchecked")
public class ValidationException extends MessagesException {

    private static final long serialVersionUID = -3597682770835261960L;

    public ValidationException(IErrorCode errorCode) {
        super(errorCode);
    }

    public ValidationException(String message) {
        super(new ErrorCode(), message);
    }

    @Override
    public void pushMessage(String message) {
        super.pushMessage(message);
    }

    @Override
    protected String getErrorMessage(Map<String, Object> error) {
        Object info = error.get("message");
        if (info instanceof List) {
            List<String> messages = (List<String>) info;
            return StringUtils.join(messages, ", ");
        }

        return info.toString() == null ? "" : info.toString();
    }

}
